<template>
  <el-dialog
      title='发票文件下载'
      ref='modal3'
      :visible.sync="dialogShow"
      width="80%"
      >
    <div >
      <div class='file-type'>
        <span class='radio-tit'>请选择下载发票的格式：</span>
        <vxe-radio-group v-model="fileType">
          <vxe-radio label="pdf" content="PDF"></vxe-radio>
          <vxe-radio label="ofd" content="OFD"></vxe-radio>
          <vxe-radio label="xml" content="XML"></vxe-radio>
        </vxe-radio-group>
      </div>
      
      <div class='box-tit'>已选择 {{ detailTableData.length }} 条发票数据。合计不含税金额{{
          bhsje
        }}元，税额{{ se }}元，价税合计{{ jshj }}元，明细如下：
      </div>

      <div style="padding: 8px 0">
        <el-button @click="downloadInvoice" type="primary">下载</el-button>
        <el-button @click="closeBox" type="primary">取消</el-button>
        </div>


      <el-table header-align="center" border :resizable="autoSize" ref="xTable2" show-header
                  :data="detailTableData">
        <el-table-column  type="index"
     label="序号" width="60" align="center"></el-table-column>
        <el-table-column prop="fphm" align="center" header-align="center" label="发票号码"></el-table-column>
        <el-table-column prop="gmfmc" align="center" header-align="center" label="购买方名称"></el-table-column>
        <el-table-column prop="hjje" align="center" header-align="center" label="不含税金额"></el-table-column>
        <el-table-column prop="hjse" align="center" header-align="center" label="税额"></el-table-column>
        <el-table-column prop="jshj" align="center" header-align="center" label="价税合计金额"></el-table-column>
        <el-table-column prop="kprq" align="center" header-align="center" label="开票日期"></el-table-column>
      </el-table>

    </div>
  </el-dialog>
</template>
<script>
import {mixin} from '@/utils/mixin.js'
import { vmsFullOutInvoiceFileDownload } from '@/api/fileDownload.js';

export default {
  name: 'downloadComp',
  mixins: [mixin],
  data() {
    return {
      dialogShow:false,
      fileType: 'pdf',
      detailTableData: [],
      autoSize: true,
      loadingTable: false,
      total: '',
      bhsje: '',
      se: '',
      jshj: ''
    }
  },
  components: {},
  // mixins: [mixin],
  created() {
  },
  mounted() {

  },
  methods: {
    closeBox() {
      this.dialogShow = false;
    },
    async downloadInvoice() {
      let detailTableData = this.detailTableData
      let arr = []
      detailTableData.map(item => {
        arr.push(item.fphm)
      })
      let params = {}
      params.downloadType = this.fileType
      params.fphms = arr;

      vmsFullOutInvoiceFileDownload( params,'post').then(() => {
      })
          .catch((error) => {
            console.error('文件下载失败:', error);
          });

    },
    show(detailTableData) {
      this.detailTableData = detailTableData;
      // let tmp = 0
      let bhsjeTmp = '0';
      let seTmp = '0';
      let jshjTmp = '0';
      detailTableData.map(item => {
        bhsjeTmp = this.bigNumAdd(bhsjeTmp,item.hjje)
        seTmp = this.bigNumAdd(seTmp,item.hjse)
        jshjTmp = this.bigNumAdd(jshjTmp,item.jshj)
      })
      // this.bhsje = bhsjeTmp.toFixed(2)
      this.bhsje = this.bigNumFixed(bhsjeTmp)
      this.se = this.bigNumFixed(seTmp)
      this.jshj = this.bigNumFixed(jshjTmp)
      // this.total = this.bigNumFixed(tmp)
      this.dialogShow = true
    }
  },
}
</script>
<style lang="scss" scoped>
.file-type {
  margin-bottom: 6px;
}
::v-deep .el-dialog__body{
  min-height: 400px ;
}
::v-deep .el-table{
  min-height: 300px ;
}

</style>